const Router = require('koa-router')
const Message = require('../schema/Message')

const msgRouter = new Router({
  prefix: '/recordApi/msg'
})

msgRouter.get('/:opCode', async ctx => {
  let opCode = ctx.params.opCode
  let msg = await Message.find({ opCode })
  ctx.body = msg
})

msgRouter.delete('/:id', async ctx => {
  let _id = ctx.params.id
  await Message.deleteOne({ _id })
  ctx.body = {
    result: 'success'
  }
})

msgRouter.delete('/clear/:opCode', async ctx => {
  let opCode = ctx.params.opCode
  await Message.deleteMany({ opCode })
  ctx.body = {
    result: 'success'
  }
})

module.exports = msgRouter